package tinybase.sm;

import tinybase.basic.RC;
import tinybase.ix.IX_Manager;
import tinybase.rm.RM_Manager;

public class QL_Manager {
    // Public
    public QL_Manager(SM_Manager smm, IX_Manager ixm, RM_Manager rmm) {

    }

    /**
     * 
     * @param nSelAttrs
     *            : # attrs in select clause
     * @param selAttrs
     *            : attrs in select clause
     * @param nRelations
     *            : # relations in from clause
     * @param relations
     *            : relations in from clause
     * @param nConditions
     *            : # conditions in from clause
     * @param conditions
     *            : conditions in from clause
     * @return
     */
    
    // Handle the select clause
    public RC select(int nSelAttrs, RelAttr[] selAttrs, int nRelations,
            String[] relations, int nConditions, Condition[] conditions) {
        
        int i;
        
        System.out.print("Select\n");
        
        System.out.print("   nSelAttrs = " + nSelAttrs + "\n");
    
        for (i = 0; i < nSelAttrs; i++)
            System.out.print("   selAttrs[" + i + "]:" + selAttrs[i] + "\n");

        System.out.print("   nRelations = " + nRelations + "\n");
        
        for (i = 0; i < nRelations; i++)
            System.out.print("   relations[" + i + "] " + relations[i] + "\n");

        System.out.print("   nCondtions = " + nConditions + "\n");
        
        for (i = 0; i < nConditions; i++)
            System.out.print("   conditions[" + i + "]:" + conditions[i] + "\n");

        return RC.SUCCESS;
        
    }

    /**
     * 
     * @param relName
     *            : relation to insert into
     * @param nValues
     *            : # values
     * @param values
     *            : values to insert
     * @return
     */
    
    // Insert the values into relName
    public RC insert(String relName, int nValues, Value[] values) {
            
        int i;

        System.out.print("Insert\n");

        System.out.print("   relName = " + relName + "\n");
        
        System.out.print("   nValues = " + nValues + "\n");
        
        for (i = 0; i < nValues; i++)
            System.out.print("   values[" + i + "]:" + values[i] + "\n");

        return RC.SUCCESS;
    
    
    }

    /**
     * 
     * @param relName
     *            : relation to delete from
     * @param nConditions
     *            : # conditions in where clause
     * @param conditions
     *            : conditions in where clause
     * @return
     */
    
    // Delete from the relName all tuples that satisfy conditions
    public RC delete(String relName, int nConditions, Condition[] conditions) {
        
        int i;

        System.out.print("Delete\n");

        System.out.print("   relName = " + relName + "\n");
        System.out.print("   nCondtions = " + nConditions + "\n");
        
        for (i = 0; i < nConditions; i++)
            System.out.print("   conditions[" + i + "]:" + conditions[i] + "\n");

        return RC.SUCCESS;
        
    }

    /**
     * 
     * @param relName
     *            : relation to update
     * @param updAttr
     *            : out, attribute to update
     * @param bIsValue
     *            : true if RHS is a value, false otherwise
     * @param rhsRelAttr
     *            : inout, attr on RHS to set LHS equal to
     * @param rhsValue
     *            : inout, value to set attr equal to
     * @param nConditions
     *            : # conditions in where clause
     * @param conditions
     *            : conditions in where clause
     * @return
     */
    
    // Update from the relName all tuples that satisfy conditions
    public RC update(String relName, RelAttr updAttr, boolean bIsValue,
            RelAttr rhsRelAttr, Value rhsValue, int nConditions,
            Condition[] conditions) {
        
        int i;

        System.out.print("Update\n");

        System.out.print("   relName = " + relName + "\n");
        
        System.out.print("   updAttr:" + updAttr + "\n");
        
        if (bIsValue)
            System.out.print("   rhs is value: " + rhsValue + "\n");
        
        else
            System.out.print("   rhs is attribute: " + rhsRelAttr + "\n");

        System.out.print("   nCondtions = " + nConditions + "\n");
        
        for (i = 0; i < nConditions; i++)
            System.out.print("   conditions[" + i + "]:" + conditions[i] + "\n");

        return RC.SUCCESS;
        
        
    }
}
